﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Pavilion
{
    public class GameController
    {
        private IView view;
        public GameSession GameSession { get; private set; }

        public void LoadGameSession(GameSession gameSession)
        {
            UnloadGameSession();

            gameSession.Load();
            this.GameSession = gameSession;
        }

        public void UnloadGameSession()
        {
            if (GameSession == null)
                return;

            GameSession.Unload();
            GameSession = null;

            ResourceManager.Instance.UnloadContent();
            DrawManager.Instance.Clear();
        }

        public void Update(GameTime gameTime)
        {
            if (GameSession != null)
                GameSession.Update(gameTime);

            if (View != null)
                View.Update(gameTime);
        }

        public void Draw()
        {
            DrawManager.Instance.Draw();
            if (View != null)
                View.Draw();
        }

        public IView View
        {
            get { return view; }
            set
            {
                if (view == value)
                    return;

                if (view != null)
                    view.Unload();

                view = value;

                if (view != null)
                    view.Load(GameSession);
            }
        }
    }
}
